<?php namespace web\admin\controller;
/** .-------------------------------------------------------------------
 * |  Software: [HDPHP framework]
 * |      Site: www.hdphp.com
 * |-------------------------------------------------------------------
 * |    Author: 向军 <2300071698@qq.com>
 * |    WeChat: aihoudun
 * | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

class Goods extends Common{
	private $db;
	public function __construct(){
		parent::__construct();
		$this->db=new \system\model\Goods;
	}
	//首页
	public function index() {
		View::with('title','商品添加');
		
		
		
		
//		获取数据返回页面
//		$data=join('type','goods.gid','=','class.cid')->get();
	$data=Db::table('goods')
    ->join('category','goods.cid','=','category.cid')
//  ->join('type','type_attr.tid','=','type.tid')
    ->get();
//  p($data);
		View::with('data',$data);
		View::make();
	}

	public function add(){
		View::with('title','商品添加');
		if(IS_POST){
//			p($_POST);die;
			$re=$this->db->store();
			if(!$re){
				message($this->db->getError());
			}
			message('添加成功','admin/goods/index');
		}
		
		
		
//		获取分类数据
		$catedata=Db::table('category')->get();
		$catedata=Data::tree($catedata,'cname','cid','pid');
//		var_dump($catedata);die;
		
		View::with('catedata',$catedata);		
//		获取品牌数据
		$branddata=Db::table('brand')->get();
		View::with('branddata',$branddata);
//		var_dump($branddata);
		View::make();
	}

//	获取分类项对应的类型属性
	public function getAttrData(){
		$tid=Q('post.tid',0,'intval');
		$arrData=Db::table('type_attr')->where('tid',$tid)->get();
//		var_dump($arrData);die;
//		将属性的内容数据转换成数组格式
		foreach($arrData as $k=>$v){
			$arrData[$k]['tavalue']=explode('|', $v['tavalue']);
		}
//		p($arrData);die;
		message($arrData,'','success');
	}
}